@import 'function';
@import 'var';

$breakpoints: (
  's': (max-width: 1100px),
  'sm': (max-width: 1200px),
  'm': (max-width: 1400px),
  'xm': (max-width: 1600px),
  'normal': (min-width: 1100px) and (max-width: 1800px),
  'l': (min-width: 1801px)
);

// 打断点的快捷写法
@mixin res($name) {
  // 循环断点Map，如果存在则返回
  @if map-has-key($breakpoints, $name) {
    @media #{inspect(map-get($breakpoints, $name))} {
      @content;
    }
  } @else {
    @warn '没有这个断点哦 `#{$breakpoints}`。';
  }
}

@function most-useful-timing() {
  @return cubic-bezier(0.4, 0, 0.2, 1);
}

@function timing($time, $delay: 0s) {
  @return $time + s $delay most-useful-timing();
}

@function tx($offsetX) {
  @return translateX($offsetX);
}

@function ty($offsetY) {
  @return translateY($offsetY);
}

@function txy($offsetX, $offsetY) {
  @return translate($offsetX, $offsetY);
}

// 字体
@mixin font-old {
  font-family: 'old-style', Baskerville, Georgia, 'Liberation Serif', 'Kaiti SC', STKaiti,
    'AR PL UKai CN', 'AR PL UKai HK', 'AR PL UKai TW', 'AR PL UKai TW MBE', 'AR PL KaitiM GB', KaiTi,
    KaiTi_GB2312, DFKai-SB, 'TW\-Kai', serif !important;
}

@function font-kai() {
  @return Baskerville, Georgia, 'Liberation Serif', 'Kaiti SC', STKaiti, 'AR PL UKai CN',
    'AR PL UKai HK', 'AR PL UKai TW', 'AR PL UKai TW MBE', 'AR PL KaitiM GB', KaiTi, KaiTi_GB2312,
    DFKai-SB, 'TW\-Kai', serif !important;
}

@function font-hei() {
  @return -apple-system, 'Noto Sans', 'Helvetica Neue', Helvetica, 'Nimbus Sans L', Arial,
    'Liberation Sans', 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Source Han Sans SC',
    'Source Han Sans CN', 'Microsoft YaHei', 'Wenquanyi Micro Hei', 'WenQuanYi Zen Hei', 'ST Heiti',
    SimHei, 'WenQuanYi Zen Hei Sharp', sans-serif;
}

@function font-song() {
  @return Georgia, 'Nimbus Roman No9 L', 'Songti SC', 'Noto Serif CJK SC', 'Source Han Serif SC',
    'Source Han Serif CN', STSong, 'AR PL New Sung', 'AR PL SungtiL GB', NSimSun, SimSun, 'TW\-Sung',
    'WenQuanYi Bitmap Song', 'AR PL UMing CN', 'AR PL UMing HK', 'AR PL UMing TW',
    'AR PL UMing TW MBE', PMingLiU, MingLiU, serif;
}

@mixin font-normal {
  font-family: -apple-system, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Arial,
    sans-serif;
}

// 最常用transition
@mixin ts {
  transition: 0.2s most-useful-timing();
}

@mixin circle($d) {
  width: $d;
  height: $d;
  border-radius: 50%;
}

@mixin paw {
  cursor: url('chrome-extension://__MSG_@@extension_id__/assets/paw.png'), pointer;
}

// 滚动条样式
@mixin non-scroll-bar {
  &::-webkit-scrollbar {
    display: none;

    &-thumb {
      display: none;
    }
  }
}

// 滚动条样式
@mixin scroll-bar {
  &::-webkit-scrollbar {
    width: 5px;
    background: #fff;

    &-thumb {
      background: $accent;
    }
  }
}

// placeholder
@mixin placeholder {
  &::-webkit-input-placeholder {
    @content;
  }
  &::-moz-placeholder {
    @content;
  }
  &:-ms-input-placeholder {
    @content;
  }
}

$B: '' !default;
$E: '' !default;

/* BEM
 -------------------------- */
@mixin b($block, $prefix: '__') {
  $B: $prefix + $block !global;

  .#{$B} {
    @content;
  }
}

@mixin e($element) {
  $E: $element !global;
  $selector: &;
  $currentSelector: '';

  @each $unit in $element {
    $currentSelector: #{$currentSelector + '.' + $B + $element-separator + $unit + ','};
  }

  @if hitAllSpecialNestRule($selector) {
    @at-root {
      #{$selector} {
        #{$currentSelector} {
          @content;
        }
      }
    }
  } @else {
    @at-root {
      #{$currentSelector} {
        @content;
      }
    }
  }
}

@mixin m($modifier) {
  $selector: &;
  $currentSelector: '';
  @each $unit in $modifier {
    $currentSelector: #{$currentSelector + & + $modifier-separator + $unit + ','};
  }

  @at-root {
    #{$currentSelector} {
      @content;
    }
  }
}

@mixin configurable-m($modifier, $E-flag: false) {
  $selector: &;
  $interpolation: '';

  @if $E-flag {
    $interpolation: $element-separator + $E-flag;
  }

  @at-root {
    #{$selector} {
      .#{$B + $interpolation + $modifier-separator + $modifier} {
        @content;
      }
    }
  }
}

@mixin spec-selector($specSelector: '', $element: $E, $modifier: false, $block: $B) {
  $modifierCombo: '';

  @if $modifier {
    $modifierCombo: $modifier-separator + $modifier;
  }

  @at-root {
    #{&}#{$specSelector}.#{$block + $element-separator + $element + $modifierCombo} {
      @content;
    }
  }
}

@mixin meb($modifier: false, $element: $E, $block: $B) {
  $selector: &;
  $modifierCombo: '';

  @if $modifier {
    $modifierCombo: $modifier-separator + $modifier;
  }

  @at-root {
    #{$selector} {
      .#{$block + $element-separator + $element + $modifierCombo} {
        @content;
      }
    }
  }
}

@mixin when($state) {
  $selector: &;

  @at-root {
    #{$selector}.#{$state-prefix + $state} {
      @content;
    }
  }
}

@mixin extend-rule($name) {
  @extend #{'%shared-' + $name};
}

@mixin share-rule($name) {
  $rule-name: '%shared-' + $name;

  @at-root #{$rule-name} {
    @content;
  }
}

@mixin pseudo($pseudo) {
  @at-root #{&}#{':#{$pseudo}'} {
    @content;
  }
}
